package com.xxz.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpSession;
@Controller
public class LoginController {
    // 登录页面请求
    @RequestMapping("/login")// 点击登录就要跳进这个请求里面
    public String login(@RequestParam("username") String username,
                        @RequestParam("password") String password,
                        Model model,
                        HttpSession session) {
        if (!StringUtils.isEmpty(username)) {
            if ("admin".equals(username)) {
                if ("999".equals(password)) {
                    session.setAttribute("loginUser", username);
                    return "redirect:xxz";
                } else {
                    model.addAttribute("msg", "密码错误");
                }
            } else {
                model.addAttribute("msg", "大哥 账号 admin");
            }
        } else {
            model.addAttribute("msg", "请输入用户名");
        }

        return "index";
//        if(!StringUtils.isEmpty (username) && "admin".equals(username) && "999".equals(password)) {
//            session.setAttribute("loginUser",username);
//            return "redirect:xxz";
//        } else {
//            // 回显错误信息
//            model.addAttribute("msg", "账号或者密码错误");
//            return "index";
//        }
    }
}